package cn.terminus.web.customer.contractrentincrementalclause.controller;

import cn.terminus.web.customer.contractrentincrementalclause.form.ContractRentIncrementalClauseNewForm;
import cn.terminus.web.customer.contractrentincrementalclause.form.ContractRentIncrementalClauseEditForm;
import cn.terminus.web.customer.contractrentincrementalclause.form.ContractRentIncrementalClauseQueryForm;
import cn.terminus.web.customer.contractrentincrementalclause.form.ContractRentIncrementalClauseDeleteForm;
import cn.terminus.web.customer.contractrentincrementalclause.form.ContractRentIncrementalClauseGetsForm;
import cn.terminus.client.customer.contractrentincrementalclause.param.ContractRentIncrementalClauseNewParam;
import cn.terminus.client.customer.contractrentincrementalclause.param.ContractRentIncrementalClauseEditParam;
import cn.terminus.client.customer.contractrentincrementalclause.param.ContractRentIncrementalClauseQueryParam;
import cn.terminus.client.customer.contractrentincrementalclause.param.ContractRentIncrementalClauseDeleteParam;
import cn.terminus.client.customer.contractrentincrementalclause.param.ContractRentIncrementalClauseGetsParam;
import cn.terminus.client.customer.contractrentincrementalclause.result.ContractRentIncrementalClauseResult;
import cn.terminus.client.customer.contractrentincrementalclause.service.ContractRentIncrementalClauseService;
import cn.terminus.result.common.result.TerminusResult;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.web.customer.common.AbstractTerminusController;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.exception.ServiceException;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import cn.terminus.result.common.util.BeanCopyUtils;
import cn.terminus.result.common.context.TerminusCallContext;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.util.List;

/**
 * 合同递增条款(ContractRentIncrementalClause)控制层
 *
 * @author makejava
 * @version 1.0.0
 * @apiDefine ContractRentIncrementalClause 合同递增条款
 * @since 2021-07-21 11:16:31
 */
@RestController
// todo 请修改path
@RequestMapping("/contractRentIncrementalClause")
@Api(value = "合同递增条款(ContractRentIncrementalClause)控制层")
public class ContractRentIncrementalClauseController extends AbstractTerminusController {
    /**
     * 服务对象
     */
    @Resource
    private ContractRentIncrementalClauseService contractRentIncrementalClauseService;

    /**
     * @api {POST} /contractRentIncrementalClause/add 合同递增条款新增
     * @apiVersion 1.0.0
     * @apiGroup ContractRentIncrementalClause
     * @apiName 合同递增条款新增
     * @apiDescription 合同递增条款新增
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Object} incrementalDate  递增时间点
     * @apiParam (RequestBody) {Double} rentalPriceIncremental  租金单价递增数量
     * @apiParam (RequestBody) {String} rentalPriceIncrementalUnitCode  租金单价递增单位code
     * @apiParam (RequestBody) {Double} depositIncremental  押金递增数量
     * @apiParam (RequestBody) {String} depositIncrementalUnitCode  押金递增单位code
     * @apiParam (RequestBody) {Integer} status  状态 1正常 2删除
     * @apiSuccess (Success 200) {String} code    状态码（00000000表示请求成功）
     * @apiSuccess (Success 200) {Boolean} success    成功
     * @apiSuccess (Success 200) {String} message    结果消息
     * @apiSuccess (Success 200) {String} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":"[]"}
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "合同递增条款新增", httpMethod = "POST")
    public TerminusResult<String> add(@RequestBody ContractRentIncrementalClauseNewForm form) {
        ContractRentIncrementalClauseNewParam param = BeanCopyUtils.copyProperties(form, ContractRentIncrementalClauseNewParam.class);
        try {
            return contractRentIncrementalClauseService.add(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("新增合同递增条款失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("新增合同递增条款失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }


    /**
     * @api {POST} /contractRentIncrementalClause/edit 合同递增条款编辑
     * @apiVersion 1.0.0
     * @apiGroup ContractRentIncrementalClause
     * @apiName 合同递增条款编辑
     * @apiDescription 合同递增条款编辑
     * @apiParam (RequestBody) {Long} id  ID
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Object} incrementalDate  递增时间点
     * @apiParam (RequestBody) {Double} rentalPriceIncremental  租金单价递增数量
     * @apiParam (RequestBody) {String} rentalPriceIncrementalUnitCode  租金单价递增单位code
     * @apiParam (RequestBody) {Double} depositIncremental  押金递增数量
     * @apiParam (RequestBody) {String} depositIncrementalUnitCode  押金递增单位code
     * @apiParam (RequestBody) {Integer} status  状态 1正常 2删除
     * @apiSuccess (Success 200) {String} code    状态码（00000000表示请求成功）
     * @apiSuccess (Success 200) {Boolean} success    成功
     * @apiSuccess (Success 200) {String} message    结果消息
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":true}
     */

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ApiOperation(value = "合同递增条款编辑", httpMethod = "POST")
    public TerminusResult<Boolean> edit(@RequestBody ContractRentIncrementalClauseEditForm form) {
        ContractRentIncrementalClauseEditParam param = BeanCopyUtils.copyProperties(form, ContractRentIncrementalClauseEditParam.class);
        try {
            return contractRentIncrementalClauseService.update(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("修改合同递增条款失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("修改合同递增条款失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractRentIncrementalClause/delete 合同递增条款删除
     * @apiVersion 1.0.0
     * @apiGroup ContractRentIncrementalClause
     * @apiName 合同递增条款删除
     * @apiDescription 合同递增条款删除
     * @apiParam (RequestBody) {String[]} ids  合同递增条款ids
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":true}
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiOperation(value = "合同递增条款删除", httpMethod = "POST")
    public TerminusResult<Boolean> delete(@RequestBody ContractRentIncrementalClauseDeleteForm form) {
        ContractRentIncrementalClauseDeleteParam param = BeanCopyUtils.copyProperties(form, ContractRentIncrementalClauseDeleteParam.class);
        try {
            return contractRentIncrementalClauseService.delete(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("删除合同递增条款失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("删除合同递增条款失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractRentIncrementalClause/gets 合同递增条款详情
     * @apiVersion 1.0.0
     * @apiGroup ContractRentIncrementalClause
     * @apiName 合同递增条款详情
     * @apiDescription 合同递增条款详情
     * @apiParam (RequestBody) {String[]} ids  合同递增条款ids
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {Object[]} data.datas    合同递增条款列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.contractId  合同ID
     * @apiSuccess (Success 200) {Object} data.datas.incrementalDate  递增时间点
     * @apiSuccess (Success 200) {Double} data.datas.rentalPriceIncremental  租金单价递增数量
     * @apiSuccess (Success 200) {String} data.datas.rentalPriceIncrementalUnitCode  租金单价递增单位code
     * @apiSuccess (Success 200) {Double} data.datas.depositIncremental  押金递增数量
     * @apiSuccess (Success 200) {String} data.datas.depositIncrementalUnitCode  押金递增单位code
     * @apiSuccess (Success 200) {Integer} data.datas.status  状态 1正常 2删除
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/gets", method = RequestMethod.POST)
    @ApiOperation(value = "合同递增条款详情查询", httpMethod = "POST")
    public TerminusResult<List<ContractRentIncrementalClauseResult>> gets(@RequestBody ContractRentIncrementalClauseGetsForm form) {
        ContractRentIncrementalClauseGetsParam param = BeanCopyUtils.copyProperties(form, ContractRentIncrementalClauseGetsParam.class);
        try {
            return contractRentIncrementalClauseService.gets(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("查询合同递增条款失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("查询合同递增条款失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractRentIncrementalClause/query 合同递增条款查询
     * @apiVersion 1.0.0
     * @apiGroup ContractRentIncrementalClause
     * @apiName 合同递增条款查询
     * @apiDescription 合同递增条款查询
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Object} incrementalDate  递增时间点
     * @apiParam (RequestBody) {Double} rentalPriceIncremental  租金单价递增数量
     * @apiParam (RequestBody) {String} rentalPriceIncrementalUnitCode  租金单价递增单位code
     * @apiParam (RequestBody) {Double} depositIncremental  押金递增数量
     * @apiParam (RequestBody) {String} depositIncrementalUnitCode  押金递增单位code
     * @apiParam (RequestBody) {Integer} status  状态 1正常 2删除
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {Object[]} data.datas    合同递增条款列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.contractId  合同ID
     * @apiSuccess (Success 200) {Object} data.datas.incrementalDate  递增时间点
     * @apiSuccess (Success 200) {Double} data.datas.rentalPriceIncremental  租金单价递增数量
     * @apiSuccess (Success 200) {String} data.datas.rentalPriceIncrementalUnitCode  租金单价递增单位code
     * @apiSuccess (Success 200) {Double} data.datas.depositIncremental  押金递增数量
     * @apiSuccess (Success 200) {String} data.datas.depositIncrementalUnitCode  押金递增单位code
     * @apiSuccess (Success 200) {Integer} data.datas.status  状态 1正常 2删除
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ApiOperation(value = "合同递增条款查询", httpMethod = "POST")
    public TerminusResult<List<ContractRentIncrementalClauseResult>> query(@RequestBody ContractRentIncrementalClauseQueryForm form) {
        ContractRentIncrementalClauseQueryParam param = BeanCopyUtils.copyProperties(form, ContractRentIncrementalClauseQueryParam.class);
        try {
            return contractRentIncrementalClauseService.query(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("查询合同递增条款失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("查询合同递增条款失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractRentIncrementalClause/page 合同递增条款分页查询
     * @apiVersion 1.0.0
     * @apiGroup ContractRentIncrementalClause
     * @apiName 合同递增条款分页查询
     * @apiDescription 合同递增条款分页查询
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Object} incrementalDate  递增时间点
     * @apiParam (RequestBody) {Double} rentalPriceIncremental  租金单价递增数量
     * @apiParam (RequestBody) {String} rentalPriceIncrementalUnitCode  租金单价递增单位code
     * @apiParam (RequestBody) {Double} depositIncremental  押金递增数量
     * @apiParam (RequestBody) {String} depositIncrementalUnitCode  押金递增单位code
     * @apiParam (RequestBody) {Integer} status  状态 1正常 2删除
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {long} data.pageSize    分页大小
     * @apiSuccess (Success 200) {long} data.currentPage    当前页
     * @apiSuccess (Success 200) {long} data.totalPages    总页数
     * @apiSuccess (Success 200) {long} data.totalRows    总记录数
     * @apiSuccess (Success 200) {long} data.minRowNumber    当页起始行号
     * @apiSuccess (Success 200) {long} data.maxRowNumber    当页最大行号
     * @apiSuccess (Success 200) {Object[]} data.datas    合同递增条款列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.contractId  合同ID
     * @apiSuccess (Success 200) {Object} data.datas.incrementalDate  递增时间点
     * @apiSuccess (Success 200) {Double} data.datas.rentalPriceIncremental  租金单价递增数量
     * @apiSuccess (Success 200) {String} data.datas.rentalPriceIncrementalUnitCode  租金单价递增单位code
     * @apiSuccess (Success 200) {Double} data.datas.depositIncremental  押金递增数量
     * @apiSuccess (Success 200) {String} data.datas.depositIncrementalUnitCode  押金递增单位code
     * @apiSuccess (Success 200) {Integer} data.datas.status  状态 1正常 2删除
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ApiOperation(value = "合同递增条款分页查询", httpMethod = "POST")
    public TerminusResult<TerminusPageAble<ContractRentIncrementalClauseResult>> page(@RequestBody ContractRentIncrementalClauseQueryForm form) {
        ContractRentIncrementalClauseQueryParam param = BeanCopyUtils.copyProperties(form, ContractRentIncrementalClauseQueryParam.class);
        try {
            TerminusPageInfo page = new TerminusPageInfo(form.getCurrentPage(), form.getRowsOfPage());
            return contractRentIncrementalClauseService.page(param, page, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("分页查询合同递增条款失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("分页查询合同递增条款失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

}
